package cn.wolfcode.trip.admin.web.controller;

import cn.wolfcode.trip.admin.util.UploadUtil;
import cn.wolfcode.trip.base.domain.TravelCommend;
import cn.wolfcode.trip.base.query.TravelCommendQueryObject;
import cn.wolfcode.trip.base.service.ITravelCommendService;
import cn.wolfcode.trip.base.util.JSONResult;
import cn.wolfcode.trip.base.util.Qiniu;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;

@Controller
public class CKEditorController {

    @RequestMapping("/uploadImage")@ResponseBody
    public Object uploadImage(MultipartFile upload){

        HashMap<String, Object> map = new HashMap<String, Object>();
        try {
            if (upload != null) {
//                String url = UploadUtil.upload(upload, UploadUtil.IMG_BASE_PATH + "/upload");
                String url = Qiniu.upLoadImage(upload.getBytes());
                map.put("uploaded",1);
                map.put("url",url);
            }
        } catch (Exception e) {
            e.printStackTrace();
            map.put("uploaded",0);
            HashMap<String, Object> errorMap = new HashMap();
            errorMap.put("message",e.getMessage());
            map.put("error",errorMap);
        }
        return map;
    }

}


